package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    public void saveOrUpdate(SystemDictionaryItem entity) {
        if(entity.getId() != null){
            systemDictionaryItemMapper.updateByPrimaryKey(entity);
        } else {
            systemDictionaryItemMapper.insert(entity);
        }
    }

    public void delete(Long id) {
        systemDictionaryItemMapper.deleteByPrimaryKey(id);
    }

    public SystemDictionaryItem get(Long id) {
        if(id != null) {
            return systemDictionaryItemMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    public List<SystemDictionaryItem> list() {
        return systemDictionaryItemMapper.selectAll();
    }

    public List<SystemDictionaryItem> selectByDictionaryId(Long id) {
        return systemDictionaryItemMapper.selectByDictionaryId(id);
    }

    public Long selectByParentId(Long id) {
        return systemDictionaryItemMapper.selectByParentId(id);
    }

    @Override
    public List<SystemDictionaryItem> getItemBySn(String sn) {
        return systemDictionaryItemMapper.getItemBySn(sn);
    }

}
